<?php
/**
 * 后台首页控制器
 */
namespace Admin\Controller;
use Think\Controller;

class IndexController extends PublicController {

    public function index() {
        $server_info = array(
                'server_os'=>PHP_OS,
                'server_env'=>$_SERVER["SERVER_SOFTWARE"],
                'uploa_max_filesize'=>ini_get('upload_max_filesize'),
                'max_execution_time'=>ini_get('max_execution_time').'秒',
                'free_space'=>round((disk_free_space(".")/(1024*1024)),2).'M',
                'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
                'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
                'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',
        );
		
        $admin_id = \admin_helper::get_admin_id();
        $admin_info = _uri('admin', $admin_id);

        //获取上一次登录信息
        $login_list = _list('login_history', array('admin_id' => $admin_id), 2, 'id desc');

        $last_login_info = $login_list[1];

        if($last_login_info){
            //登录设备
            $login_source = $last_login_info['login_source'];
            if(1 == $login_source){
                $last_login_info['login_source'] = '电脑';
            }elseif(2 == $login_source){
                $last_login_info['login_source'] = '手机';
            }elseif(3 == $login_source){
                $last_login_info['login_source'] = '微信';
            }

            //登录地址
            $login_ip = $last_login_info['login_ip'];
            if($login_ip){
                $last_login_info['login_address'] = get_ip_address($login_ip);
            }

            $this->assign('last_login_info', $last_login_info);

        }

    	$this->assign('server_info', $server_info);
    	$this->assign('admin_info', $admin_info);
		
    	$this->display('index');

    }

    //清除缓存
    public function  clear(){

        \config_helper::clear_cache();

        $this->success('缓存文件清除成功');

    }
}